/*
 * gerador.c
 *
 *  Created on: 02/03/2013
 *      Author: marcio
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <time.h>

#define PI 3.14159265


void genUniforme(long prob, FILE* out, long n){
	long elems[n];
	long size = 0;
	long pn = prob;
	srand (time(NULL));
	long i;
	for( i = 0; i < n; i++){
		if((rand()%100) < pn) elems[size++] = i;
	}
	fprintf(out, "%lu \n", n);
	fprintf(out, "%lu \n", size);
	for( i = 0; i < size; i++){
		fprintf(out, "%lu \n", elems[i]);
	}
}

void genPoisson(long prob, FILE* out, long n){
	long elems[n];
	long size = 0;
	long pn;
	srand (time(NULL));
	long i;
	for(i = 0; i < n; i++){
		pn = (long)( 100 * cos( (((float)i)/((float)n))* PI/2.0) );
		pn = (pn*prob)/100;
		if((rand()%100) < pn) elems[size++] = i;
	}
	fprintf(out, "%lu \n", n);
	fprintf(out, "%lu \n", size);
	for(i = 0; i < size; i++){
		fprintf(out, "%lu \n", elems[i]);
	}
}


void genEp(long prob, FILE* out, long n){
	long elems[n];
	long size = 0;
	long pn = (prob*n)/100;
	srand (time(NULL));
	long i;
	for(i = 0; i < n; i++){
		if(((rand()%100) < 50) && (pn > i)) elems[size++] = i;
	}
	fprintf(out, "%lu \n", n);
	fprintf(out, "%lu \n", size);
	for(i = 0; i < size; i++){
		fprintf(out, "%lu \n", elems[i]);
	}
}


int main(){
	FILE* out;

	out = fopen("1-zeros_1_100000.txt", "w");
	genEp(1, out, 10000);
	fclose(out);

	out = fopen("1-zeros_1_1000000.txt", "w");
	genEp(1, out, 100000);
	fclose(out);

	out = fopen("1-zeros_1_10000000.txt", "w");
	genEp(1, out, 1000000);
	fclose(out);

	out = fopen("2-zeros_1_100000.txt", "w");
	genEp(1, out, 10000);
	fclose(out);

	out = fopen("2-zeros_1_1000000.txt", "w");
	genEp(1, out, 100000);
	fclose(out);

	out = fopen("2-zeros_1_10000000.txt", "w");
	genEp(1, out, 1000000);
	fclose(out);

	return 0;
}
